import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/route_manager.dart';
import 'package:star_author/config/ui_constant.dart';
import 'package:star_author/widgets/custom_image/custom_image.dart';
import 'package:star_author/widgets/empty_view/h_empty_view.dart';
import 'package:star_author/widgets/empty_view/v_empty_view.dart';

///讲解人选择列表
class AnchorSelectListBottomSheet extends StatelessWidget {
  const AnchorSelectListBottomSheet(this.studioDetailMap, this.selectCallback,
      {Key? key})
      : super(key: key);
  final Function selectCallback;
  final Map studioDetailMap;

  @override
  Widget build(BuildContext context) {
    return Container(
        constraints: BoxConstraints(
          minHeight: 320.w,
          maxHeight: 375.w,
        ),
        padding: EdgeInsets.only(
            bottom: MediaQuery.of(context).padding.bottom + 10.w),
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(12.w),
              topRight: Radius.circular(12.w),
            )),
        child: Stack(
          children: [
            Positioned(
              child: GestureDetector(
                child: Container(
                  alignment: Alignment.topRight,
                  child: Text(
                    "返回",
                    style: TextStyle(
                      fontSize: 12.sp,
                      color: UIConstant.color99,
                    ),
                  ),
                  padding: EdgeInsets.only(
                    left: 12.w,
                    right: 12.w,
                    top: 10.w,
                  ),
                ),
                onTap: () {
                  Get.back();
                },
                behavior: HitTestBehavior.opaque,
              ),
            ),
            Column(
              children: [
                Container(
                  alignment: Alignment.center,
                  child: Text(
                    "请选择主播",
                    style: TextStyle(
                        fontSize: 16.sp,
                        color: Color(0xFF333333),
                        fontWeight: FontWeight.w500),
                  ),
                  margin: EdgeInsets.only(
                    left: 12.w,
                    top: 25.w,
                  ),
                ),
                VEmptyView(25.w),
                Expanded(
                  flex: 1,
                  child: ListView.builder(
                    itemBuilder: (ctx, index) {
                      var item = studioDetailMap['select_anchors_list'][index];

                      bool isLiving = false;
                      if (studioDetailMap['living_anchor'] != null &&
                          studioDetailMap['living_anchor']['id'] != null &&
                          studioDetailMap['living_anchor']['id'] ==
                              item['id']) {
                        isLiving = true;
                      }

                      return GestureDetector(
                        behavior: HitTestBehavior.opaque,
                        onTap: () {
                          selectCallback(item);
                          Get.back();
                        },
                        child: Container(
                          height: 48.w,
                          margin: EdgeInsets.symmetric(
                            vertical: 5.w,
                            horizontal: 12.w,
                          ),
                          padding: EdgeInsets.only(
                            left: 18.w,
                            right: 14.w,
                          ),
                          decoration: BoxDecoration(
                            color: UIConstant.colorF6F6,
                            borderRadius: BorderRadius.all(
                              Radius.circular(8.w),
                            ),
                          ),
                          child: Row(
                            children: [
                              CustomImage.loadAvatarUrl(
                                "${item['avatar']}",
                                width: 24.w,
                              ),
                              HEmptyView(8.w),
                              Text(
                                "${item['nickname']}",
                                style: TextStyle(
                                  color: UIConstant.color33,
                                  fontSize: 14.sp,
                                ),
                              ),
                              Expanded(
                                child: Container(),
                                flex: 1,
                              ),
                              Container(
                                width: 28.w,
                                height: 12.w,
                                decoration: BoxDecoration(
                                  borderRadius: BorderRadius.all(
                                    Radius.circular(2.w),
                                  ),
                                  color: isLiving
                                      ? Color(0xffFEBA07)
                                      : UIConstant.colorCC,
                                ),
                                alignment: Alignment.center,
                                child: Text(
                                  isLiving ? "直播中" : "休息中",
                                  style: TextStyle(
                                    fontSize: 8.sp,
                                    color: Colors.white,
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      );
                    },
                    itemCount:
                        studioDetailMap['select_anchors_list'].length ?? 0,
                  ),
                ),
              ],
            ),
          ],
        ));
  }
}
